package cn.lanqiao.demo.service.impl;

import cn.lanqiao.demo.dao.StudentDao;
import cn.lanqiao.demo.entity.Student;
import cn.lanqiao.demo.service.StudentService;
import cn.lanqiao.demo.vo.StudentVaccineVo;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 学生业务层
 */
@Service
public class StudentServiceImpl implements StudentService {
    @Resource
    private StudentDao studentDao;

    //根据sno查询学生
    @Override
    @Transactional(propagation = Propagation.REQUIRED,readOnly = true)  //事务注解，事务传播机制为REQUIRED，设置只读属性
    public StudentVaccineVo getStudentBySno(String sno) {
        return studentDao.getStudentBySno(sno);
    }

    //查询所有学生
    @Override
    @Transactional(propagation = Propagation.REQUIRED,readOnly = true)
    public List<StudentVaccineVo> getAllStudents() {
        return studentDao.getAllStudents();
    }

    //添加学生
    @Override
    public int addStudent(Student student) {
        return studentDao.addStudent(student);
    }

    //删除学生
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public int deleteStudent(String sno) {
        return studentDao.deleteStudent(sno);
    }

    //修改学生
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public int updateStudent(Student student) {
        return studentDao.updateStudent(student);
    }

    //学生分页
    @Override
    public List<Student> getList(int pageNum, int pageSize) {
        //使用分页插件,核心代码
        PageHelper.startPage(pageNum, pageSize);
        //获取查询数据
        List<Student> typeList = studentDao.getList();
        return typeList;
    }
}
